const tree = {
    val: "a",
    children: [
        {
            val: "b",
            children: [{
                val: "d",
                children: []
            }, {
                val: "e",
                children: []
            }]
        },
        {
            val: "c",
            children: [{
                val: "f",
                children: []
            }, {
                val: "g",
                children: []
            }]
        }
    ]
}
// 访问根节点，对根节点的children依次深度优先遍历
const dfs=(root)=>{
    console.log(root);
    if(root.children){
        root.children.forEach((e)=>{
            dfs(e)
        })
    }
}
dfs(tree)